package com.lab.base.dao;

import com.lab.base.model.Page;
import com.lab.base.vo.Parameter;
import org.hibernate.HibernateException;

import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public interface IBaseDao<T> {

    //单个CRUD
    void save(final T entity) throws Exception;

    void delete(final T entity) throws Exception;

    void deleteWithHql(final String hql) throws Exception;

    void update(final T entity) throws Exception;

    T getOne(final int id) throws Exception;

    int batchSave(final List<T> list) throws Exception;

    void deleteAll(final Collection entities) throws Exception;

    //createQuery（Query）
    T findOne(final String hql) throws Exception;

    T findOne(final String hql, final Parameter parameter) throws Exception;

    //list查询
    List<T> findList(final String hql) throws Exception;

    List<T> findList(final String hql, final Parameter parameter) throws Exception;

    //分页查询
    Page<T> findPage(final int currentPage, final int pageSize, final String queryHql, final String countHql, final Object[] values)
            throws HibernateException, SQLException;

    Page<T> findPage(final int currentPage, final int pageSize, final String queryHql, final String countHql)
            throws HibernateException, SQLException;

    //查询满足条件的记录数
    long findCount(final String hql);

    long findCount(final String hql, final Object[] values);
}
